{"componentChunkName":"component---src-templates-post-jsx","path":"/[BOJ]9935/","result":{"data":{"site":{"siteMetadata":{"title":"SUbbb"}},"markdownRemark":{"id":"1d132410-9377-5e55-85b9-4664ff64de73","excerpt":"문제 상근이는 문자열에 폭발 문자열을 심어 놓았다. 폭발 문자열이 폭발하면 그 문자는 문자열에서 사라지며, 남은 문자열은 합쳐지게 된다. 폭발은 다음과 같은 과정으로 진행된다. 문자열이 폭발 문자열을 포함하고 있는 경우에, 모든 폭발 문자열이 폭발하게 된다. 남은 문자열을 순서대로 이어 붙여 새로운 문자열을 만든다. 새로 생긴 문자열에 폭발 문자열이 포함…","html":"<h2>문제</h2>\n<p>상근이는 문자열에 폭발 문자열을 심어 놓았다. 폭발 문자열이 폭발하면 그 문자는 문자열에서 사라지며, 남은 문자열은 합쳐지게 된다.</p>\n<p>폭발은 다음과 같은 과정으로 진행된다.</p>\n<ul>\n<li>문자열이 폭발 문자열을 포함하고 있는 경우에, 모든 폭발 문자열이 폭발하게 된다. 남은 문자열을 순서대로 이어 붙여 새로운 문자열을 만든다.</li>\n<li>새로 생긴 문자열에 폭발 문자열이 포함되어 있을 수도 있다.</li>\n<li>폭발은 폭발 문자열이 문자열에 없을 때까지 계속된다.</li>\n</ul>\n<p>상근이는 모든 폭발이 끝난 후에 어떤 문자열이 남는지 구해보려고 한다. 남아있는 문자가 없는 경우가 있다. 이때는 \"FRULA\"를 출력한다.</p>\n<p>폭발 문자열은 같은 문자를 두 개 이상 포함하지 않는다.</p>\n<h3>입력</h3>\n<ul>\n<li>첫째 줄에 문자열이 주어진다. 문자열의 길이는 1보다 크거나 같고, 1,000,000보다 작거나 같다.</li>\n<li>둘째 줄에 폭발 문자열이 주어진다. 길이는 1보다 크거나 같고, 36보다 작거나 같다.</li>\n<li>두 문자열은 모두 알파벳 소문자와 대문자, 숫자 0, 1, ..., 9로만 이루어져 있다.</li>\n</ul>\n<h3>출력</h3>\n<ul>\n<li>첫째 줄에 모든 폭발이 끝난 후 남은 문자열을 출력한다.</li>\n</ul>\n<h2>📍 <strong>Logic</strong></h2>\n<deckgo-highlight-code language=\"java\" terminal=\"carbon\" theme=\"a11y-dark\" line-numbers=\"true\"  >\n          <code slot=\"code\"></code>\n        </deckgo-highlight-code>\n<ul>\n<li></li>\n</ul>\n<h3>📄 <strong>CODE</strong></h3>\n<details>\n  <summary>코드 보기/접기💫</summary>\n    <div markdown=\"1\">\n<deckgo-highlight-code  terminal=\"carbon\" theme=\"a11y-dark\" line-numbers=\"true\"  >\n          <code slot=\"code\">import java.util.*;\n\nclass Graph {\n    final int[] graph;\n    int[] discovered;\n    boolean[] fin;\n    int answer = 0;\n    int graph_size;\n\n    public Graph(int size) {\n        graph_size = size + 1;\n        this.graph = new int[graph_size];\n        discovered = new int[graph_size];\n        fin = new boolean[graph_size];\n    }\n\n    public void AddElement(int x, int y) {\n        graph[x] = y;\n    }\n\n    public int solution() {\n        for (int i=1; i &lt; graph_size; i++) this.search(i);\n        return graph_size - 1 - this.answer;\n    }\n\n    public void search(int node) {\n        if (discovered[node] == 1) return;\n\n        discovered[node] = 1;\n        int next = graph[node];\n\n        if (discovered[next] == 0) search(graph[node]);\n        else {\n            if (!fin[next]) {\n                // 다음 갈 정점이 방문은 했으나 아직 끝나지 않은, 즉 사이클이 생성되지 않은 상태\n                answer++;\n                for (int i=next; i!=node; i=graph[i]) {\n                    answer++;\n                }\n            }\n        }\n        fin[node] = true;\n    }\n}\n\npublic class Main {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int T = sc.nextInt();\n\n        while (T &gt; 0) {\n            int size = sc.nextInt();\n\n            Graph g = new Graph(size);\n\n            for (int i = 1; i &lt;= size; i++) {\n                int tmp = sc.nextInt();\n                g.AddElement(i, tmp);\n            }\n\n            System.out.println(g.solution());\n            T-=1;\n        }\n        sc.close();\n    }\n}</code>\n        </deckgo-highlight-code>\n  \t</div>\n</details>\n<h3>✏️ <strong>Review</strong></h3>\n<ul>\n<li>\n<p>처음에는 <code class=\"language-text\">replaceAll()</code> 함수를 사용해서 매우 간단한 코드로 구현했으나, 47%에서 메모리 초과가 떴다.</p>\n<ul>\n<li>당연히 이렇게 쉬울 리는 없다고 생각했고, 게시판을 보니 <code class=\"language-text\">replace()</code> 함수가 메모리를 많이 사용하는 메소드라는 것을 알았다.</li>\n</ul>\n</li>\n<li></li>\n</ul>\n<h3>📕 출처</h3>\n<p>Baekjoon : <a href=\"https://www.acmicpc.net/problem/9935\">https://www.acmicpc.net/problem/9935</a></p>","frontmatter":{"title":"👩‍💻 9935. 문자열 폭발","date":"April 20, 2022","update":"April 20, 2022","tags":["문자열","자료구조","스택"],"series":"👩‍💻 BOJ"},"fields":{"slug":"/[BOJ]9935/","readingTime":{"minutes":3.455}}},"seriesList":{"edges":[{"node":{"id":"27733333-3aad-5771-a1a1-27b4de4b4a01","fields":{"slug":"/[BOJ]2225/"},"frontmatter":{"title":"👩‍💻 2225. 합분해"}}},{"node":{"id":"548ba188-2afe-5575-b79f-107c6c65b07d","fields":{"slug":"/[BOJ]1012/"},"frontmatter":{"title":"👩‍💻 1012. 유기농 배추"}}},{"node":{"id":"0c712680-130f-5fa5-8c3b-3632dd5d1af0","fields":{"slug":"/[BOJ]1260/"},"frontmatter":{"title":"👩‍💻 1260. DFS와 BFS"}}},{"node":{"id":"0e07a592-06ce-5e01-b5e1-95398330372e","fields":{"slug":"/[BOJ]1707/"},"frontmatter":{"title":"👩‍💻 1707. 이분그래프"}}},{"node":{"id":"df12bfec-ed5c-5fc4-8442-0a4b3f9759a3","fields":{"slug":"/[BOJ]2668/"},"frontmatter":{"title":"👩‍💻 2668. 숫자 고르기"}}},{"node":{"id":"01bbb6dc-812c-5223-87c5-53bf04c0d0a6","fields":{"slug":"/[BOJ]9466/"},"frontmatter":{"title":"👩‍💻 9466. 텀 프로젝트"}}},{"node":{"id":"abc306b3-c3a6-552a-8979-e82d506b3921","fields":{"slug":"/[BOJ]2146/"},"frontmatter":{"title":"👩‍💻 2146. 다리 만들기"}}},{"node":{"id":"b3394e53-5e9a-595e-8da4-bb3debd220c0","fields":{"slug":"/[BOJ]5014/"},"frontmatter":{"title":"👩‍💻 5014. 스타트 링크"}}},{"node":{"id":"be297703-e778-5727-8019-6954bc95da3a","fields":{"slug":"/[BOJ]11559/"},"frontmatter":{"title":"👩‍💻 11559. Puyo Puyo"}}},{"node":{"id":"ddf11545-d468-5269-94b1-5daa2720e886","fields":{"slug":"/[BOJ]17471/"},"frontmatter":{"title":"👩‍💻 17471. 게리맨더링"}}},{"node":{"id":"8d77114d-fc6e-5de2-a3ca-c3b250425a56","fields":{"slug":"/[BOJ]2437/"},"frontmatter":{"title":"👩‍💻 2437. 저울"}}},{"node":{"id":"9a8942ce-552f-51ae-b304-0d0fab8f2eba","fields":{"slug":"/[BOJ]14891/"},"frontmatter":{"title":"👩‍💻 14891. 톱니바퀴"}}},{"node":{"id":"f1c04e8a-df0a-5294-949f-5f3a483cbcb0","fields":{"slug":"/[BOJ]14503/"},"frontmatter":{"title":"👩‍💻 14503. 로봇 청소기"}}},{"node":{"id":"883b6ecf-7528-5c16-92fa-edf12a64e80e","fields":{"slug":"/[BOJ]3190/"},"frontmatter":{"title":"👩‍💻 3190. 뱀"}}},{"node":{"id":"099b2576-7d05-5872-a9f0-f1ee6efd3a9a","fields":{"slug":"/[BOJ]14502/"},"frontmatter":{"title":"👩‍💻 14502. 연구소"}}},{"node":{"id":"50eef059-4e55-5f14-a9cf-fb01b6506f02","fields":{"slug":"/[BOJ]17779/"},"frontmatter":{"title":"👩‍💻 17779. 게리맨더링 2"}}},{"node":{"id":"aa67d90b-4801-574c-b225-56c23737a5e2","fields":{"slug":"/[BOJ]2579/"},"frontmatter":{"title":"👩‍💻 2579. 계단 오르기"}}},{"node":{"id":"9db6b43b-963a-5ebd-b72b-69936cf37858","fields":{"slug":"/[BOJ]14499/"},"frontmatter":{"title":"👩‍💻 14499. 주사위 굴리기"}}},{"node":{"id":"6a79cddd-dc1b-5e34-8a84-af313c37de0e","fields":{"slug":"/[BOJ]15685/"},"frontmatter":{"title":"👩‍💻 15685. 드래곤 커브"}}},{"node":{"id":"5e001d34-d985-545b-83ec-7f1c7caea286","fields":{"slug":"/[BOJ]17144/"},"frontmatter":{"title":"👩‍💻 17144. 미세먼지 안녕!"}}},{"node":{"id":"1d132410-9377-5e55-85b9-4664ff64de73","fields":{"slug":"/[BOJ]9935/"},"frontmatter":{"title":"👩‍💻 9935. 문자열 폭발"}}},{"node":{"id":"e13ff8d6-9b02-56c0-83e2-1d3144f70e1d","fields":{"slug":"/[BOJ]16472/"},"frontmatter":{"title":"👩‍💻 16472. 고냥이"}}},{"node":{"id":"0f782160-aaa9-5c54-80c0-72a15172dd16","fields":{"slug":"/[BOJ]1083/"},"frontmatter":{"title":"👩‍💻 1083. 소트"}}},{"node":{"id":"fef58615-9e18-5f50-8d09-3d1e2839342f","fields":{"slug":"/[BOJ]20922/"},"frontmatter":{"title":"👩‍💻 20922. 겹치는 건 싫어"}}},{"node":{"id":"7ca89240-c65f-5cb4-aeef-c5f1605ebd00","fields":{"slug":"/[BOJ]16172/"},"frontmatter":{"title":"👩‍💻 16172. 나는 친구가 적다(Large)"}}}]},"previous":{"fields":{"slug":"/[BackEnd]Docker배포/"},"frontmatter":{"title":"💻 Docker를 이용한 Springboot 배포"}},"next":{"fields":{"slug":"/[Programmers]42862/"},"frontmatter":{"title":"👩‍💻 42862. 체육복"}}},"pageContext":{"id":"1d132410-9377-5e55-85b9-4664ff64de73","series":"👩‍💻 BOJ","previousPostId":"b945159a-d6ce-5269-a463-898869856e12","nextPostId":"9da2693a-dfe4-59c6-9388-f61498de5717"}},"staticQueryHashes":[]}